package jfuzzyprincepless.zarchive.algorithm.structure;

import java.util.List;
import java.util.ArrayList;

import jfuzzyprincepless.agents.INegotiatingAgent;
import jfuzzyprincepless.negotiation.IExecutionContext;
import jfuzzyprincepless.negotiation.INegotiation;
import jfuzzyprincepless.negotiation.INegotiationContext;
import jfuzzyprincepless.negotiation.impl.OverrideInCopyContext;
import jfuzzyprincepless.zarchive.negotiation.protocols.INegotiationProtocol__Q_del;
import jfuzzyprincepless.zarchive.negotiation.ZArchNegotiationUtils;

// TODO: rename 2 BaseNegotiationCommandConstruction [ BaseNegotiationCmdConst ]
public abstract class BaseNegotiationConstruction
	extends DefaultConstruction
	implements ICommandConstruction
{
	protected INegotiationProtocol__Q_del protocol =
		ZArchNegotiationUtils.newDefaultNegotiationProtocol();

	protected BaseNegotiationConstruction(
		List<INegotiatingAgent> agents
	) {
		super(agents);
	}

	protected BaseNegotiationConstruction() {
		this(new ArrayList<INegotiatingAgent>());
	}

	public abstract void extractAgentsFromConstructions();

	public void setProtocol(INegotiationProtocol__Q_del protocol) {
		this.protocol = protocol;
	}

	@Override
	public void execute(IExecutionContext econtext) {
		INegotiationContext context =
			(INegotiationContext)econtext;
		context = new OverrideInCopyContext(context);
		INegotiation negotiation =
			protocol.createNegotiation(this, context);
		negotiation.negotiate(context);
		negotiation.execute(context);
	}
}
